/**
 * 
 */
package cn.jhz.filesharingsystem.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.jhz.filesharingsystem.model.Pager;
import cn.jhz.filesharingsystem.model.Role;

/**
 * RoleDao的实现类
 * @author asus
 */
@Repository("roleDao")
public class RoleDaoImpl extends BaseDaoImpl<Role> implements RoleDao {


	@Override
	public List<Role> getAllRoles(boolean state) {
		String hql = "FROM Role r WHERE 1=1 ";
		if(state) {
			hql+="AND r.roleName != 'super' AND r.roleName != 'admin'";
		}
		return super.list(hql, null, null);
	}

	@Override
	public Pager<Role> getAllPagerRoles(boolean state) {
		String hql = "FROM Role r WHERE 1=1 ";
		
		if(state) {
			hql+="AND r.roleName != 'super' AND r.roleName != 'admin'";
		}
		
		return super.find(hql, null, null);
	}
	
	@Override
	public Role getRoleByName(String roleName) {
		String hql = "SELECT r FROM Role r WHERE r.roleName=?0";
		return (Role) super.queryByHql(hql, new Object[] {roleName}, null);
	}
}
